package com.hauwei.huaweishop.controller;

import com.hauwei.huaweishop.entity.Admins;
import com.hauwei.huaweishop.service.AdminsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/admins")
@CrossOrigin
public class AdminsController {

    @Autowired
    private AdminsService adminsService;

    /**
     * 登录
     * @param admins
     * @return
     */
    @RequestMapping("/adminLogin")
    public Map<String, Object> adminLogin(@RequestBody Admins admins){
        log.info("管理员信息：[{}]", admins);
        Map<String, Object> resultMap = new HashMap<>();
        try {
            Admins adminsDB = adminsService.adminstoLogin(admins);
            resultMap.put("status", true);
            resultMap.put("msg", "提示：登录成功");
            resultMap.put("adminsDB", adminsDB);
        }catch (Exception e){
            resultMap.put("status", false);
            resultMap.put("msg", "提示："+e.getMessage());
        }
        return resultMap;
    }
}
